<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>09 字体 | HasakWebBlog</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="hasak">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.a5a0d673.css" as="style"><link rel="preload" href="/assets/js/app.c7915c77.js" as="script"><link rel="preload" href="/assets/js/3.f80332a6.js" as="script"><link rel="preload" href="/assets/js/1.5cffa4a1.js" as="script"><link rel="preload" href="/assets/js/19.417d2070.js" as="script"><link rel="prefetch" href="/assets/js/10.02ae8499.js"><link rel="prefetch" href="/assets/js/11.c5238d8f.js"><link rel="prefetch" href="/assets/js/12.be21fd80.js"><link rel="prefetch" href="/assets/js/13.bd684308.js"><link rel="prefetch" href="/assets/js/14.b5f9fc77.js"><link rel="prefetch" href="/assets/js/15.318683dc.js"><link rel="prefetch" href="/assets/js/16.74f9d94e.js"><link rel="prefetch" href="/assets/js/17.cd1e6d69.js"><link rel="prefetch" href="/assets/js/18.901e5492.js"><link rel="prefetch" href="/assets/js/20.39ec66a2.js"><link rel="prefetch" href="/assets/js/21.fbf1aaf8.js"><link rel="prefetch" href="/assets/js/22.736aeb98.js"><link rel="prefetch" href="/assets/js/23.abcdc310.js"><link rel="prefetch" href="/assets/js/24.26658596.js"><link rel="prefetch" href="/assets/js/25.40bdc691.js"><link rel="prefetch" href="/assets/js/26.29ac009b.js"><link rel="prefetch" href="/assets/js/27.edc6afbf.js"><link rel="prefetch" href="/assets/js/28.b9c1065e.js"><link rel="prefetch" href="/assets/js/29.b46f8f9e.js"><link rel="prefetch" href="/assets/js/30.6839ae7e.js"><link rel="prefetch" href="/assets/js/31.85913f4e.js"><link rel="prefetch" href="/assets/js/32.098b21df.js"><link rel="prefetch" href="/assets/js/33.faced894.js"><link rel="prefetch" href="/assets/js/34.239b19e7.js"><link rel="prefetch" href="/assets/js/35.5c8a8406.js"><link rel="prefetch" href="/assets/js/36.46f0ebac.js"><link rel="prefetch" href="/assets/js/37.2456f410.js"><link rel="prefetch" href="/assets/js/38.b76624ee.js"><link rel="prefetch" href="/assets/js/39.64ecef14.js"><link rel="prefetch" href="/assets/js/4.7d7a493e.js"><link rel="prefetch" href="/assets/js/40.a1304a44.js"><link rel="prefetch" href="/assets/js/41.f98208ce.js"><link rel="prefetch" href="/assets/js/42.f0be4a4c.js"><link rel="prefetch" href="/assets/js/43.1a46f61e.js"><link rel="prefetch" href="/assets/js/44.d579b00f.js"><link rel="prefetch" href="/assets/js/45.8e8ea47a.js"><link rel="prefetch" href="/assets/js/46.1b194721.js"><link rel="prefetch" href="/assets/js/47.994c7d71.js"><link rel="prefetch" href="/assets/js/48.f17a641c.js"><link rel="prefetch" href="/assets/js/49.0d9ea06f.js"><link rel="prefetch" href="/assets/js/5.176296fc.js"><link rel="prefetch" href="/assets/js/50.e36885a9.js"><link rel="prefetch" href="/assets/js/51.64538ee2.js"><link rel="prefetch" href="/assets/js/52.1fd24c2e.js"><link rel="prefetch" href="/assets/js/53.967b1458.js"><link rel="prefetch" href="/assets/js/54.05b15a98.js"><link rel="prefetch" href="/assets/js/55.3c78b9d4.js"><link rel="prefetch" href="/assets/js/56.8d130c30.js"><link rel="prefetch" href="/assets/js/57.0008c022.js"><link rel="prefetch" href="/assets/js/58.4b49a382.js"><link rel="prefetch" href="/assets/js/59.8bb182dc.js"><link rel="prefetch" href="/assets/js/6.90835ce9.js"><link rel="prefetch" href="/assets/js/60.93235335.js"><link rel="prefetch" href="/assets/js/61.78370acd.js"><link rel="prefetch" href="/assets/js/62.1144f314.js"><link rel="prefetch" href="/assets/js/63.7fb72cd2.js"><link rel="prefetch" href="/assets/js/64.de8ba1be.js"><link rel="prefetch" href="/assets/js/65.cefa274d.js"><link rel="prefetch" href="/assets/js/66.32ad44bf.js"><link rel="prefetch" href="/assets/js/67.558c356c.js"><link rel="prefetch" href="/assets/js/68.15a3af19.js"><link rel="prefetch" href="/assets/js/69.b1b26c0a.js"><link rel="prefetch" href="/assets/js/7.2c075495.js"><link rel="prefetch" href="/assets/js/70.cb9b8e94.js"><link rel="prefetch" href="/assets/js/71.e371986a.js"><link rel="prefetch" href="/assets/js/72.a8af9117.js"><link rel="prefetch" href="/assets/js/73.dcc5a1af.js"><link rel="prefetch" href="/assets/js/74.803a909b.js"><link rel="prefetch" href="/assets/js/75.8129f8f6.js"><link rel="prefetch" href="/assets/js/76.ffcb07fc.js"><link rel="prefetch" href="/assets/js/8.9b4cfefe.js"><link rel="prefetch" href="/assets/js/9.e529cf11.js">
    <link rel="stylesheet" href="/assets/css/0.styles.a5a0d673.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-7dd95ae2><div data-v-7dd95ae2><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>HasakWebBlog</h3> <p class="description" data-v-59e6cb88>hasak</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>hasak</span>
          
        <span data-v-59e6cb88>2022 - </span>
        2023
      </a></span></div></div> <div class="hide" data-v-7dd95ae2><header class="navbar" data-v-7dd95ae2><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="HasakWebBlog" class="logo"> <span class="site-name">HasakWebBlog</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      前端学习
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/HTML5&amp;CSS3/" class="nav-link"><i class="undefined"></i>
  HTML5&amp;CSS3
</a></li><li class="dropdown-item"><!----> <a href="/categories/Javascript/" class="nav-link"><i class="undefined"></i>
  Javascript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node/" class="nav-link"><i class="undefined"></i>
  Node
</a></li><li class="dropdown-item"><!----> <a href="/categories/VUE/" class="nav-link"><i class="undefined"></i>
  VUE
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tags
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/hasakxu" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-7dd95ae2></div> <aside class="sidebar" data-v-7dd95ae2><div class="personal-info-wrapper" data-v-1fad0c41 data-v-7dd95ae2><img src="/dog.png" alt="author-avatar" class="personal-img" data-v-1fad0c41> <h3 class="name" data-v-1fad0c41>
    hasak
  </h3> <div class="num" data-v-1fad0c41><div data-v-1fad0c41><h3 data-v-1fad0c41>66</h3> <h6 data-v-1fad0c41>Articles</h6></div> <div data-v-1fad0c41><h3 data-v-1fad0c41>5</h3> <h6 data-v-1fad0c41>Tags</h6></div></div> <ul class="social-links" data-v-1fad0c41></ul> <hr data-v-1fad0c41></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      前端学习
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/HTML5&amp;CSS3/" class="nav-link"><i class="undefined"></i>
  HTML5&amp;CSS3
</a></li><li class="dropdown-item"><!----> <a href="/categories/Javascript/" class="nav-link"><i class="undefined"></i>
  Javascript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node/" class="nav-link"><i class="undefined"></i>
  Node
</a></li><li class="dropdown-item"><!----> <a href="/categories/VUE/" class="nav-link"><i class="undefined"></i>
  VUE
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tags
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/hasakxu" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>HTML5&amp;CSS3 学习</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blogs/基础/html/20221107html01.html" class="sidebar-link">01 字符实体与语义标签</a></li><li><a href="/blogs/基础/html/20221107html02.html" class="sidebar-link">02 CSS语法与选择器</a></li><li><a href="/blogs/基础/html/20221110html03.html" class="sidebar-link">03 样式继承与其他概念</a></li><li><a href="/blogs/基础/html/20221110html04.html" class="sidebar-link">04 盒模型</a></li><li><a href="/blogs/基础/html/20221110html05.html" class="sidebar-link">05 盒模型补充</a></li><li><a href="/blogs/基础/html/20221113html06.html" class="sidebar-link">06 浮动</a></li><li><a href="/blogs/基础/html/20221113html07.html" class="sidebar-link">07 高度塌陷与BFC</a></li><li><a href="/blogs/基础/html/20221113html08.html" class="sidebar-link">08 定位</a></li><li><a href="/blogs/基础/html/20221115html09.html" class="active sidebar-link">09 字体</a></li><li><a href="/blogs/基础/html/20221115html10.html" class="sidebar-link">10 背景</a></li><li><a href="/blogs/基础/html/20221115html11.html" class="sidebar-link">11 雪碧图和渐变</a></li><li><a href="/blogs/基础/html/20221115html12.html" class="sidebar-link">12 表格</a></li><li><a href="/blogs/基础/html/20221115html13.html" class="sidebar-link">13 过渡与动画</a></li><li><a href="/blogs/基础/html/20221115html14.html" class="sidebar-link">14 变形：平移、旋转与缩放</a></li><li><a href="/blogs/基础/html/20221115html15.html" class="sidebar-link">15 LESS简介</a></li><li><a href="/blogs/基础/html/20221115html16.html" class="sidebar-link">16 弹性盒简介</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>09 字体</h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>hasak</span>
          
        <span data-v-59e6cb88>2022 - </span>
        2023
      </a></span></div></div> <div data-v-7dd95ae2><div data-v-7dd95ae2><main class="page" style="padding-right:0;"><section style="display:;"><div class="page-title"><h1 class="title">09 字体</h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>hasak</span></i> <i class="iconfont reco-date" data-v-8a445198><span data-v-8a445198>6/19/2022</span></i> <!----> <i class="tags iconfont reco-tag" data-v-8a445198><span class="tag-item" data-v-8a445198>CSS</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="_09-字体"><a href="#_09-字体" class="header-anchor">#</a> 09 字体</h1> <h2 id="_1-字体相关的样式"><a href="#_1-字体相关的样式" class="header-anchor">#</a> 1.字体相关的样式</h2> <p>字体具有两个属性</p> <ul><li><code>color</code> 用来设置字体颜色</li> <li><code>font-size</code>用来设置字体的大小
<ul><li><code>em</code>相当于当前元素的一个<code>font-size</code></li> <li><code>rem</code>相对于根元素的一个<code>font-size</code></li></ul></li></ul> <h2 id="_2-font-family"><a href="#_2-font-family" class="header-anchor">#</a> 2. font-family</h2> <p>字体族（字体的样式）</p> <p>包括了</p> <ul><li><code>serif</code> 衬线字体</li> <li><code>sans-serif</code> 非衬线字体</li> <li><code>monospace</code> 等宽字体</li> <li><code>cursive</code> 手写体</li> <li><code>fantasy</code>梦幻字体</li></ul> <p><code>font-family</code>可以同时指定多个字体，多个字体间用 <code>,</code>隔开，字体生效时优先使用第一个，第一个无法使用则使用第二个，以此类推</p> <h3 id="font-face"><a href="#font-face" class="header-anchor">#</a> @font-face</h3> <p>除了这些固定的字体之外，<code>@font-face</code>可以将服务器中的字体直接提供给用户去使用</p> <div class="language-CSS line-numbers-mode"><pre class="language-css"><code><span class="token atrule"><span class="token rule">@font-face</span></span>   <span class="token punctuation">{</span>
    <span class="token property">font-family</span><span class="token punctuation">:</span><span class="token string">'myfont1'</span><span class="token punctuation">;</span>
    <span class="token comment">/*服务器中字体路径*/</span>
    <span class="token comment">/*format 告诉浏览器字体格式，一般不写*/</span>
    <span class="token property">src</span><span class="token punctuation">:</span> <span class="token url"><span class="token function">url</span><span class="token punctuation">(</span><span class="token string url">'./font/ZCOOLKuaile-Regular.woff'</span><span class="token punctuation">)</span></span><span class="token punctuation">,</span>
        <span class="token url"><span class="token function">url</span><span class="token punctuation">(</span><span class="token string url">'./font/ZCOOLKuaile-Regular.otf'</span><span class="token punctuation">)</span></span><span class="token punctuation">,</span>
        <span class="token url"><span class="token function">url</span><span class="token punctuation">(</span><span class="token string url">'./font/ZCOOLKuaile-Regular.ttf'</span><span class="token punctuation">)</span></span> <span class="token function">format</span><span class="token punctuation">(</span><span class="token string">'truetype'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        
<span class="token punctuation">}</span>

<span class="token selector">p</span> <span class="token punctuation">{</span>
    <span class="token property">font-size</span><span class="token punctuation">:</span>30px<span class="token punctuation">;</span>
    <span class="token property">color</span><span class="token punctuation">:</span>salmon<span class="token punctuation">;</span>
    <span class="token property">font-family</span><span class="token punctuation">:</span>myfont1<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p><strong>缺点：</strong></p> <ol><li>加载速度：收网络速度影响，可能会出现字体闪烁以下然后变成最终的字体</li> <li>版权：有些字体商用需要收费</li> <li>字体格式：未必兼容，可能需要指定多个字体格式</li></ol> <h2 id="_3-图标字体-iconfont"><a href="#_3-图标字体-iconfont" class="header-anchor">#</a> 3. 图标字体（iconfont）</h2> <p>网页中经常需要使用一些图标</p> <p>通过图片来引入图标，会因为图片本身比较大，并且非常的不灵活，放大还会有马赛克。所以再使用图标时，我们可以将图标设置为字体，这样就是矢量图了。</p> <p>通过<code>@font-face</code>的形式对字体进行引入，也可以通过字体的形式来使用图标</p> <h3 id="fontawesome"><a href="#fontawesome" class="header-anchor">#</a> <strong>fontawesome</strong></h3> <p>官方网站：<a href="https:fontawesome.com" target="_blank" rel="noopener noreferrer">https:fontawesome.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>下载解压完毕后，直接将CSS和webfonts文件夹移动到项目中即可，并将all.css引入到网页中</p> <ul><li>直接通过类名来使用图标字体 class=“fab fa-weixin fa-lg&quot;, 其中 `fas/fab是免费的，其他是收费的</li></ul> <h3 id="iconfont"><a href="#iconfont" class="header-anchor">#</a> iconfont</h3> <p>官方网站：<a href="https://www.iconfont.cn" target="_blank" rel="noopener noreferrer">https://www.iconfont.cn<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h3 id="图标字体其他使用方式"><a href="#图标字体其他使用方式" class="header-anchor">#</a> 图标字体其他使用方式</h3> <p><strong>1.通过伪元素设置</strong></p> <ol><li>找到要设置的图标，通过<code>::before</code>或者 <code>::after</code>进行选中</li> <li>在 <code>content</code>中设置字体的编码</li> <li>设置字体样式
<ul><li><code>fab</code>: <code>font-family: 'Font Awesome 5 Brands';</code></li> <li><code>fas</code>: <code>font-family: 'Font Awesome 5 Free' ; font-weight:900;</code></li></ul></li></ol> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.poem</span> <span class="token punctuation">{</span>
        <span class="token property">width</span><span class="token punctuation">:</span>200px<span class="token punctuation">;</span>
        <span class="token property">height</span><span class="token punctuation">:</span>300px<span class="token punctuation">;</span>
        <span class="token property">margin</span><span class="token punctuation">:</span>auto<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">li</span> <span class="token punctuation">{</span>
        <span class="token property">list-style</span><span class="token punctuation">:</span>none<span class="token punctuation">;</span>
        <span class="token property">margin-left</span><span class="token punctuation">:</span>-40px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">li::before</span> <span class="token punctuation">{</span>
        <span class="token property">content</span><span class="token punctuation">:</span><span class="token string">'\f130'</span><span class="token punctuation">;</span>
        <span class="token property">font-family</span><span class="token punctuation">:</span> <span class="token string">'Font Awesome 5 Free'</span> <span class="token punctuation">;</span>
        <span class="token property">font-weight</span><span class="token punctuation">:</span>900<span class="token punctuation">;</span>
        <span class="token property">margin-right</span><span class="token punctuation">:</span>10px<span class="token punctuation">;</span>
        <span class="token property">color</span><span class="token punctuation">:</span>gray<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>poem<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">&gt;</span></span>
        武陵春·春晚
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
        [宋] 李清照
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>风烛尘香花已尽，<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>日晚倦梳头。<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>物是人非事事休，<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>欲语泪先流。<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>闻说双溪春尚好，<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>也拟泛轻舟。<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>只恐双溪舴艋舟，<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>载不动，许多愁。<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br></div></div><p><img src="https://hasakwebblogimg.oss-cn-hangzhou.aliyuncs.com/202211151625486.png" alt="font1"></p> <p><strong>2. 通过类元素</strong></p> <div class="language-CSS line-numbers-mode"><pre class="language-css"><code>&lt;i class=<span class="token string">&quot;fas fa-cat&quot;</span>&gt;&lt;/li&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img src="https://hasakwebblogimg.oss-cn-hangzhou.aliyuncs.com/202211151626303.png" alt="font2"></p> <p><strong>3. 通过实体设置</strong></p> <p>通过实体，比如图像编码进行引入</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>fas<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token entity" title="&amp;#xf6be;">&amp;#xf6be;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>i</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img src="https://hasakwebblogimg.oss-cn-hangzhou.aliyuncs.com/202211151627985.png" alt="font2"></p> <h2 id="_4-行高"><a href="#_4-行高" class="header-anchor">#</a> 4. 行高</h2> <h3 id="行高-line-height"><a href="#行高-line-height" class="header-anchor">#</a> 行高 line-height</h3> <p>文字占有的实际高度，可以通过<code>line-height</code>来设置行高</p> <ol><li>可以指定一个大小 <code>px/em</code></li> <li>可以直接为行高设置一个小数（字体大小的倍数）</li></ol> <p>行高还继经常用来设置文字的行间距： <code>行间距 = 行高 - 字体大小</code></p> <h3 id="字体框"><a href="#字体框" class="header-anchor">#</a> 字体框</h3> <p>就是字体存在的格子，设置 <code>font-size</code>实际上就是在设置字体框的高度</p> <p><img src="https://hasakwebblogimg.oss-cn-hangzhou.aliyuncs.com/202211151631828.png" alt="font3"></p> <ul><li><p>行高会在字体框的上下平均分配</p></li> <li><p>不指定行高时，<code>content</code>高度 <code>131.566px</code>: 说明 <code>line-height</code>默认值大概是1.31~1.32（倍数）</p></li> <li><p>指定行高时，<code>content</code>高度为<code>99.556px</code>: 少了<code>0.444px</code>，并且字母<code>p</code>下面溢出</p></li></ul> <h2 id="_5-字体的简写属性"><a href="#_5-字体的简写属性" class="header-anchor">#</a> 5. 字体的简写属性</h2> <p><code>font</code>可以设置字体相关的所有属性</p> <p><code>font: font-style font-variant font-weight font-size/line/height font-family</code></p> <p>其中有些值可以不写。会直接用默认值</p> <table><thead><tr><th style="text-align:center;">属性</th> <th></th> <th style="text-align:center;">默认值</th> <th>其他常用值</th></tr></thead> <tbody><tr><td style="text-align:center;"><code>font-style</code></td> <td>样式</td> <td style="text-align:center;"><code>normal</code></td> <td><code>italic</code></td></tr> <tr><td style="text-align:center;"><code>font-variant</code></td> <td></td> <td style="text-align:center;"><code>normal</code></td> <td><code>small-caps</code></td></tr> <tr><td style="text-align:center;"><code>font-weight</code></td> <td>粗细</td> <td style="text-align:center;"><code>normal</code></td> <td><code>bold</code></td></tr> <tr><td style="text-align:center;"><code>font-size</code></td> <td>字大小</td> <td style="text-align:center;"><code>medium</code></td> <td><code>small</code> <code>large</code></td></tr> <tr><td style="text-align:center;"><code>line-height</code></td> <td>行高</td> <td style="text-align:center;"><code>normal</code></td> <td></td></tr> <tr><td style="text-align:center;"><code>font-family</code></td> <td>字体</td> <td style="text-align:center;">取决于浏览器</td> <td></td></tr></tbody></table> <h2 id="_6-文本对齐方式"><a href="#_6-文本对齐方式" class="header-anchor">#</a> 6.文本对齐方式</h2> <h3 id="水平对齐-text-align"><a href="#水平对齐-text-align" class="header-anchor">#</a> 水平对齐 （text-align）</h3> <table><thead><tr><th style="text-align:center;">属性值</th> <th style="text-align:center;">对齐方式</th></tr></thead> <tbody><tr><td style="text-align:center;"><code>left</code></td> <td style="text-align:center;">左侧对齐</td></tr> <tr><td style="text-align:center;"><code>right</code></td> <td style="text-align:center;">右侧对齐</td></tr> <tr><td style="text-align:center;"><code>center</code></td> <td style="text-align:center;">居中对齐</td></tr> <tr><td style="text-align:center;"><code>justify</code></td> <td style="text-align:center;">两端对齐</td></tr></tbody></table> <h3 id="垂直对齐-vertical-align"><a href="#垂直对齐-vertical-align" class="header-anchor">#</a> 垂直对齐（vertical-align）</h3> <table><thead><tr><th style="text-align:center;">属性值</th> <th style="text-align:center;">对齐方式</th></tr></thead> <tbody><tr><td style="text-align:center;"><code>baseline</code></td> <td style="text-align:center;">基线对齐</td></tr> <tr><td style="text-align:center;"><code>top</code></td> <td style="text-align:center;">顶部对齐</td></tr> <tr><td style="text-align:center;"><code>bottom</code></td> <td style="text-align:center;">底部对齐</td></tr> <tr><td style="text-align:center;"><code>middle</code></td> <td style="text-align:center;">居中对齐</td></tr></tbody></table> <p><strong><code>vertical-align</code>还可以设置px值来设置垂直对齐方式</strong>（也可以用于图片对齐）</p> <h2 id="_7-文本修饰"><a href="#_7-文本修饰" class="header-anchor">#</a> 7. 文本修饰</h2> <p><code>text-decoration</code>文本修饰</p> <ul><li><code>none</code>什么都没有</li> <li><code>underline</code>下划线</li> <li><code>line-through</code>删除线</li> <li><code>over-line</code>上划线</li></ul> <p><code>white-space</code>设置网页如何处理空白</p> <ul><li><code>normal</code>默认值，换行</li> <li><code>nowrap</code>不换行</li> <li><code>pre</code> 保留文本原始格式，多个空格 换行都保留</li></ul> <h2 id="_8-练习"><a href="#_8-练习" class="header-anchor">#</a> 8. 练习</h2> <div class="language-html line-numbers-mode"><pre class="language-html"><code>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></section> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/blogs/基础/html/20221113html08.html" class="prev">
          08 定位
        </a></span> <span class="next"><a href="/blogs/基础/html/20221115html10.html">
          10 背景
        </a></span></p></div> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:0;" data-v-b57cc07c data-v-7dd95ae2></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/assets/js/app.c7915c77.js" defer></script><script src="/assets/js/3.f80332a6.js" defer></script><script src="/assets/js/1.5cffa4a1.js" defer></script><script src="/assets/js/19.417d2070.js" defer></script>
  </body>
</html>
